/**
 * Created by zzy on 2016/12/8.
 */
var $ = require('jquery');
require('easyui');
require('layout/uiJs');
var $alert = require("libs/alert");
var isSale = require('libs/user-type').isSale;
$(function () {
    $('#ft').show();
    var status = {
        new: '新建',
        committed: '已提交',
        picking: '拣货中',
        pick: '已拣货',
        packing: '装箱中',
        pack: '已装箱',
        weight: '已称重',
        waitOut: '待出库',
        outroom: '已出库',
        cancelled: '已取消'
    };
    $('#search').on('click',function () {
        var formData = $('#searchForm').serializeObject();
        formData.submitDtFrom = $('#startDt1').data('utc0');
        formData.submitDtTo = $('#endDt1').data('utc0');
        formData.outDateFrom = $('#startDt2').data('utc0');
        formData.outDateTo = $('#endDt2').data('utc0');
        $('#mainTable').datagrid('load',formData);
    });
    $(document).on('click','a[name=orderDetail]',function () {
        window.parent.tabOpen($(this).attr('ref'),'FBA订单详情',true,true);
    });
    $(document).on('click','a[name=entDetail]',function () {
        window.parent.tabOpen($(this).attr('ref'),'客户公司',true,true);
    });

    warehouseInit();
    tableInit();
    function warehouseInit() {
        $('select[name=warehouseId]').combobox({
            url:'api/v1/p/crm/warehouse/query',
            valueField:'warehouseId',
            textField:'warehouseName',
            queryParams:{
                warehouseType:'DEST'
            },
            loadFilter:function(result){
                if(result.code=='200'){
                    result.data.unshift({warehouseId:'',warehouseName:'全部'});
                    return result.data;
                }
            }
        })
    }
    function tableInit() {
        $('#mainTable').datagrid({
            url:'api/v1/p/mms/fbaTransportOrder/list',
            border : false,
            height:$(window).height(),
            pagination : true,
            pageSize : 20,
            pageList : [ 20, 50,  100 ],
            emptyMsg : "暂无数据",
            singleSelect: true,
            rownumbers:true,
            columns:[[
                {
                    field:'orderNo',
                    title:'FBA订单号',
                    width:'12%',
                    formatter:function (value,row,index) {
                        return "<a class='ellipsis' href='javascript:;' ref='fba-transorder-detail?id="+row.id+"' name='orderDetail' title='"+value+"'>"+value+"</a>";
                    }
                },{
                    field:'entName',
                    title:'客户名称',
                    width:'10%',
                    formatter:function (value,row,index) {
                        return "<a class='ellipsis' href='javascript:;' ref='company-detail?id="+row.entId+"' name='entDetail' title='"+value+"'>"+value+"</a>";
                    }
                },
                {
                    field:'warehouseName',
                    title:'海外仓',
                    width:'10%',
                    formatter:function (value,row,index) {
                        return "<div class='ellipsis' title='"+value+"'>"+value+"</div>";
                    }
                },{
                    field:'fbaWarehouseName',
                    title:'FBA仓',
                    width:'10%',
                    formatter:function (value,row,index) {
                        return "<div class='ellipsis' title='"+value+"'>"+value+"</div>";
                    }
                },{
                    field:'deliveryWay',
                    title:'物流承运商',
                    width:'11%',
                    formatter:function (value,row,index) {
                        return "<div class='ellipsis' title='"+value+"'>"+value+"</div>";
                    }
                },{
                    field:'skuNums',
                    title:'SKU数量',
                    width:'5%',
                    formatter:function (value,row,index) {
                        return "<div class='ellipsis' title='"+value+"'>"+value+"</div>";
                    }
                },{
                    field:'tNums',
                    title:'商品总数',
                    width:'5%'
                },{
                    field:'submitDt',
                    title:'提交时间',
                    width:'15%',
                    formatter:function (value,row,index) {
                        return "<div class='ellipsis' title='"+value+"'>"+value+"</div>";
                    }
                },{
                    field:'outroomDt',
                    title:'出库时间',
                    width:'15%',
                    formatter:function (value,row,index) {
                        return "<div class='ellipsis' title='"+value+"'>"+value+"</div>";
                    }
                },{
                    field:'status',
                    title:'状态',
                    width:'7%',
                    formatter:function (value,row,index) {
                        return status[value];
                    }
                }
            ]],
            loadFilter:function(data){
                if(data.code == '200'){
                    return data.data;
                }else{
                    return [];
                }
            },
            toolbar:"#tb"
        });
    }
});
